namespace QMVnSoft.Opening
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCDKHO0Lister : FormOpenningLister
    {
        private IContainer components;
        private CDKHODataAccess oMethod;

        public FormCDKHO0Lister()
        {
            this.oMethod = new CDKHODataAccess();
            this.InitializeComponent();
        }

        public FormCDKHO0Lister(bool pb_CheckDetailMost) : base(pb_CheckDetailMost)
        {
            this.oMethod = new CDKHODataAccess();
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x31a, 0x214);
            base.Name = "FormCDKHO0Lister";
            this.Text = "Tồn thực tế đầu kỳ kho: VT - Vật tư";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private object[][] InsertArray(object[][] aSource, object[] aNewRow)
        {
            object[][] objArray = new object[aSource.GetLength(0) + 1][];
            for (int i = 0; i < aSource.GetLength(0); i++)
            {
                object[] objArray2 = new object[aNewRow.GetLength(0)];
                for (int j = 0; j < aNewRow.GetLength(0); j++)
                {
                    objArray2[j] = aSource[i][j];
                }
                objArray[i] = objArray2;
            }
            int length = aSource.GetLength(0);
            objArray[length] = aNewRow;
            return objArray;
        }

        protected override void OnAdd()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                base.LocalFormEditor = new FormCDKHOEditor();
                base.OnAdd();
            }
        }

        protected override void OnDelete()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((base.DataGridBrowser.CurrentRow != null) && (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                if ((base.DataGridBrowser.SelectedRows != null) && (base.DataGridBrowser.SelectedRows.Count != 0))
                {
                    foreach (DataGridViewRow row in base.DataGridBrowser.SelectedRows)
                    {
                        DataRow row2 = ((DataRowView) row.DataBoundItem).Row;
                        if (this.oMethod.Delete(row2["Stt0"]))
                        {
                            base.LocalTable.Rows.Remove(row2);
                        }
                    }
                }
                else
                {
                    DataRow row3 = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row;
                    if (this.oMethod.Delete(row3["Stt0"]))
                    {
                        base.LocalTable.Rows.Remove(row3);
                    }
                }
                base.LocalTable.AcceptChanges();
            }
        }

        protected override void OnEdit()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                base.LocalFormEditor = new FormCDKHOEditor();
                base.OnEdit();
            }
        }

        protected override void OnGenerateColumns()
        {
            if (base.LocalParentRow == null)
            {
                this.Text = "Tồn kho đầu kỳ thực tế";
            }
            else
            {
                this.Text = "Tồn thực tế đầu kỳ kho: " + base.LocalParentRow["Ma_Kho"].ToString() + " - " + base.LocalParentRow["Ten_Kho"].ToString();
            }
            object[][] objArray = new object[1][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Ngay_Ct";
            objArray2[1] = "Ngày";
            objArray2[2] = "D";
            objArray[0] = objArray2;
            base.LocalColNames = objArray;
            if (AppInstance.LocationCtrl)
            {
                object[] objArray3 = new object[4];
                objArray3[0] = "Ma_Ke";
                objArray3[1] = "Kệ hàng";
                objArray3[2] = "C";
                base.LocalColNames = this.InsertArray(base.LocalColNames, objArray3);
            }
            object[] aNewRow = new object[4];
            aNewRow[0] = "Ma_Vt";
            aNewRow[1] = "Mã vật tư";
            aNewRow[2] = "C";
            base.LocalColNames = this.InsertArray(base.LocalColNames, aNewRow);
            object[] objArray5 = new object[4];
            objArray5[0] = "Ten_Vt";
            objArray5[1] = "Tên vật tư";
            objArray5[2] = "C";
            base.LocalColNames = this.InsertArray(base.LocalColNames, objArray5);
            object[] objArray6 = new object[4];
            objArray6[0] = "Dvt";
            objArray6[1] = "Đvt";
            objArray6[2] = "C";
            base.LocalColNames = this.InsertArray(base.LocalColNames, objArray6);
            base.LocalColNames = this.InsertArray(base.LocalColNames, new object[] { "So_Luong", "Số lượng", "N", AppInstance.TextNumericFormat.Quantity });
            if (AppInstance.LotNumberCtrl)
            {
                object[] objArray8 = new object[4];
                objArray8[0] = "Lo_Hang";
                objArray8[1] = "L\x00f4 hàng";
                objArray8[2] = "C";
                base.LocalColNames = this.InsertArray(base.LocalColNames, objArray8);
            }
            if (AppInstance.DeadLineCtrl)
            {
                object[] objArray9 = new object[4];
                objArray9[0] = "Han_Dung";
                objArray9[1] = "Hạn d\x00f9ng";
                objArray9[2] = "D";
                base.LocalColNames = this.InsertArray(base.LocalColNames, objArray9);
            }
            if (AppInstance.QualityCtrl)
            {
                base.LocalColNames = this.InsertArray(base.LocalColNames, new object[] { "H_Luong", "H\x00e0m lượng", "N", AppInstance.TextNumericFormat.Percent });
            }
            if (AppInstance.DampCtrl)
            {
                base.LocalColNames = this.InsertArray(base.LocalColNames, new object[] { "Do_Am_PT", "Độ ẩm", "N", AppInstance.TextNumericFormat.Percent });
            }
            if (AppInstance.AlcoholCtrl)
            {
                base.LocalColNames = this.InsertArray(base.LocalColNames, new object[] { "Do_Con_PT", "Độ cồn", "N", AppInstance.TextNumericFormat.Percent });
            }
            base.OnGenerateColumns();
        }

        protected override void OnRefresh()
        {
            if (base.LocalParentRow == null)
            {
                base.LocalTable = this.oMethod.GetDataTable(AppInstance.Subsidiary, "");
            }
            else
            {
                base.LocalTable = this.oMethod.GetDataTable(AppInstance.Subsidiary, base.LocalParentRow["Ma_Kho"]);
            }
            base.OnRefresh();
        }
    }
}

